import { BasicColumn } from '@/components/Table';
import { FormSchema, commonRules } from '@/components/Form';
import { useRender } from '@/hooks/component/useRender';
import { InputNumber } from 'ant-design-vue';
import { VxeGridPropTypes, VxeTablePropTypes } from 'vxe-table';
import { getDictOptions } from '@/utils/dict';
import { DictEnum } from '@/enums/dictEnum';

const { renderDict } = useRender();
export const formSchems: FormSchema[] = [
  {
    label: '产品名称',
    field: 'spuName',
    component: 'Input',
  },
  {
    label: '创建日期',
    field: 'dateRange',
    component: 'RangePicker',
    colProps: { span: 10 },
    componentProps: {
      placeholder: ['开始日期', '结束日期'],
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
    },
  },
];

export const columns: BasicColumn[] = [
  {
    title: '商品编号#',
    dataIndex: 'spuNo',
  },
  {
    title: '商品名称',
    dataIndex: 'spuName',
  },
  {
    title: '封面图',
    dataIndex: 'spuCoverImage',
  },
  {
    title: '产品分组',
    dataIndex: 'spuTypeId',
    customRender: ({ value }) => {
      return renderDict(value, DictEnum.SPU_TYPE);
    },
  },
  {
    title: '状态',
    dataIndex: 'spuIsShelves',
    customRender: ({ value }) => {
      return renderDict(value, DictEnum.SPU_STATUS);
    },
  },
  {
    title: '价格',
    dataIndex: 'price',
  },
  {
    title: '起订量',
    dataIndex: 'spuMinOrderNum',
  },
];

export const drawerSchemas: FormSchema[] = [
  {
    label: '产品ID',
    field: 'spuId',
    required: false,
    component: 'Input',
    show: false,
  },
  {
    label: '产品名称',
    field: 'spuName',
    required: true,
    component: 'Input',
  },
  {
    label: '分组',
    field: 'spuTypeId',
    required: true,
    component: 'Select',
    componentProps: {
      allowClear: false,
      options: getDictOptions(DictEnum.SPU_TYPE),
    },
  },
  {
    label: '产品编号',
    field: 'spuNo',
    required: true,
    component: 'Input',
  },
  {
    label: '概述',
    field: 'spuDesc',
    required: true,
    component: 'InputTextArea',
    componentProps: {
      rows: 3,
    },
  },
  {
    label: '产品描述',
    field: 'spuDetail',
    required: true,
    component: 'InputTextArea',
    componentProps: {
      rows: 3,
    },
  },
  {
    label: '关键字',
    field: 'spuKeyWord',
    required: false,
    slot: 'spuKeyWord',
    colProps: { span: 24 },
  },
  {
    label: '颜色',
    field: 'spuColor',
    required: true,
    component: 'Select',
    componentProps: {
      allowClear: false,
      options: getDictOptions(DictEnum.SPU_COLOR),
    },
  },
  {
    label: '主题',
    field: 'topicId',
    required: true,
    component: 'Select',
    componentProps: {
      allowClear: false,
      options: getDictOptions(DictEnum.SPU_TOPIC),
    },
  },
  {
    label: '产品尺寸',
    field: 'spuSize',
    rules: commonRules('default', false),
    slot: 'spuSize',
    colProps: { span: 24 },
    itemProps: {
      autoLink: false,
    },
  },
  {
    label: '产品重量',
    field: 'spuWeight',
    rules: commonRules('default', false),
    slot: 'spuWeight',
    itemProps: {
      autoLink: false,
    },
  },
  {
    label: '材质',
    field: 'spuMaterial',
    required: false,
    component: 'Select',
    componentProps: {
      allowClear: false,
      options: getDictOptions(DictEnum.SPU_MATERIAL),
    },
  },
  {
    label: '产地',
    field: 'spuMadeIn',
    required: false,
    component: 'Select',
    componentProps: {
      allowClear: false,
      options: getDictOptions(DictEnum.COUNTRY),
    },
  },
];

export const drawerSchemas1: FormSchema[] = [
  {
    label: 'skuId',
    field: 'skuId',
    required: false,
    component: 'Input',
    show: false,
  },
  {
    label: '印刷方式',
    field: 'skuPrintTypeId',
    required: true,
    component: 'Select',
    // show: false,
    colProps: { span: 24 },
    componentProps: {
      allowClear: false,
      options: getDictOptions(DictEnum.PRINT_MODE),
    },
  },
  {
    label: '印刷尺寸',
    field: 'spuSize1',
    required: false,
    slot: 'spuSize1',
    itemProps: {
      autoLink: false,
    },
  },
  {
    label: '位置',
    field: 'skuPrintPosition',
    required: true,
    component: 'Select',
    componentProps: {
      allowClear: false,
      options: getDictOptions(DictEnum.PRINT_POSITION),
    },
  },
  {
    label: '印刷尺寸2',
    field: 'spuSize2',
    required: false,
    slot: 'spuSize2',
    itemProps: {
      autoLink: false,
    },
  },
  {
    label: '位置2',
    field: 'skuPrintPosition2',
    required: false,
    component: 'Select',
    componentProps: {
      allowClear: false,
      options: getDictOptions(DictEnum.PRINT_POSITION),
    },
  },
];
export const drawerSchemas2: FormSchema[] = [
  {
    label: '包装方式',
    field: 'packingTypeId',
    required: true,
    component: 'Select',
    // show: false,
    colProps: { span: 8 },
    componentProps: {
      allowClear: false,
      options: getDictOptions(DictEnum.PRINT_MODE),
    },
  },
  {
    label: '装箱数量',
    field: 'packingNum',
    required: true,
    colProps: { span: 8 },
    component: 'InputNumber',
  },
  {
    label: '装箱重量',
    field: 'packageWeight',
    required: false,
    slot: 'packageWeight',
    colProps: { span: 8 },
    itemProps: {
      autoLink: false,
    },
  },
  {
    label: '装箱尺寸',
    field: 'packageSize',
    required: false,
    slot: 'packageSize',
    itemProps: {
      autoLink: false,
    },
    colProps: { span: 24 },
  },
  {
    label: '生产天数',
    field: 'produceDay',
    required: false,
    slot: 'produceDay',
    itemProps: {
      autoLink: false,
    },
  },
  {
    label: '加急天数',
    field: 'urgentDay',
    required: false,
    slot: 'urgentDay',
    itemProps: {
      autoLink: false,
    },
  },
];
export const drawerSchemas3: FormSchema[] = [
  // {
  //   label: '价格包含',
  //   field: 'test1',
  //   required: true,
  //   slot: 'test1',
  //   colProps: { span: 20 },
  //   itemProps: {
  //     autoLink: false,
  //   },
  // },
  // {
  //   label: '包含运费',
  //   field: 'test2',
  //   required: true,
  //   colProps: { span: 4 },
  //   component: 'Checkbox',
  // },
  {
    label: '价格编码',
    field: 'priceCodeId',
    required: true,
    component: 'Select',
    // show: false,
    componentProps: {
      allowClear: false,
      options: getDictOptions(DictEnum.PRICE_CODE),
    },
  },
  {
    label: '价格区间',
    field: 'priceList',
    required: false,
    slot: 'priceList',
    itemProps: {
      autoLink: false,
    },
    colProps: { span: 24 },
  },

  {
    label: '制版费 US$',
    field: 'plateCost',
    required: false,
    slot: 'plateCost',
    itemProps: {
      autoLink: false,
    },
  },
  {
    label: '单位',
    field: 'test6',
    required: false,
    component: 'Select',
    // show: false,
    componentProps: {
      allowClear: false,
      options: getDictOptions(DictEnum.SYS_UNIT),
    },
  },
];

export const vxeTableColumns: VxeGridPropTypes.Columns = [
  {
    type: 'checkbox',
    align: 'center',
    width: 60,
  },
  {
    title: '序号',
    type: 'seq',
    fixed: 'left',
    width: '50',
    align: 'center',
  },
  {
    title: '最小起订量',
    field: 'miniOrder',
    slots: {
      edit: ({ row }) => {
        return (
          <InputNumber
            v-model:value={row.miniOrder}
            min={1}
            max={99999}
            placeholder="请输入最小起订量"
          ></InputNumber>
        );
      },
    },
    editRender: {},
  },
  {
    title: '价格',
    field: 'price',
    slots: {
      edit: ({ row }) => {
        return (
          <InputNumber
            v-model:value={row.price}
            min={1}
            max={99999}
            placeholder="请输入价格"
          ></InputNumber>
        );
      },
    },
    editRender: {},
  },
];

export const validRules: VxeTablePropTypes.EditRules = {
  num: [{ required: true, message: '请输入最小起订量' }],
  price: [{ required: true, message: '请输入价格' }],
};

export const drawerSchemas4: FormSchema[] = [
  {
    label: '商品主图',
    field: 'imageWithLogo',
    required: false,
    slot: 'imageWithLogo',
    colProps: { span: 24 },
  },
  {
    label: '详情图片',
    field: 'productDetailImages',
    required: false,
    slot: 'productDetailImages',
    colProps: { span: 24 },
  },
];
